// @ts-nocheck
/* eslint-disable */
import { request } from '@umijs/max';

// 创建银行卡
export async function createCard(body: any, options?: { [key: string]: any }) {
  return request('/api/admin/cards', {
    method: 'POST',
    data: body,
    ...(options || {}),
  });
}

// 查询银行卡列表
export async function getCardList(params?: any, options?: { [key: string]: any }) {
  return request('/api/cards', {
    method: 'GET',
    params,
    ...(options || {}),
  });
}

// 挂失/解挂银行卡
export async function reportLossCard(card_id: string, body: { is_report_loss: number }, options?: { [key: string]: any }) {
  return request(`/api/cards/${card_id}/report-loss`, {
    method: 'PUT',
    data: body,
    ...(options || {}),
  });
}

/** 存款 */
export async function depositToCard(card_id: string, amount: number) {
  return request(`/api/cards/${card_id}/deposit`, {
    method: 'POST',
    data: { amount },
  });
}

/** 取款 */
export async function withdrawFromCard(card_id: string, amount: number, password: string) {
  return request(`/api/cards/${card_id}/withdraw`, {
    method: 'POST',
    data: { amount, password },
  });
}

// 分页查询银行卡列表
export async function getCardPage(params: {
  page?: number;
  size?: number;
  userId?: number;
  cardId?: string;
  isReportLoss?: number;
  startTime?: string;
  endTime?: string;
}, options?: { [key: string]: any }) {
  console.log('Debug - cardController getCardPage params:', params);
  try {
    const response = await request('/api/admin/cards/page', {
      method: 'GET',
      params,
      ...(options || {}),
    });
    console.log('Debug - cardController getCardPage response:', response);
    return response;
  } catch (error) {
    console.error('Debug - cardController getCardPage error:', error);
    throw error;
  }
}

// 切换银行卡挂失状态
export async function toggleReportLoss(cardId: string, isReportLoss: number, options?: { [key: string]: any }) {
  return request(`/api/admin/cards/${cardId}/report-loss`, {
    method: 'PUT',
    params: { isReportLoss },
    ...(options || {}),
  });
}

// 删除银行卡
export async function deleteCard(cardId: string, options?: { [key: string]: any }) {
  return request(`/api/admin/cards/${cardId}`, {
    method: 'DELETE',
    ...(options || {}),
  });
}

// 修改银行卡密码
export async function updateCardPassword(body: { cardId: string; oldPassword: string; newPassword: string }, options?: { [key: string]: any }) {
  return request('/api/admin/cards/password', {
    method: 'PUT',
    data: body,
    ...(options || {}),
  });
} 